package com.whut.customer.shiro;

import com.whut.customer.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * 获取当前的登录用户
 */

public class SecurityUser {

    public static Subject getSubject(){
        try{
            return SecurityUtils.getSubject();
        }catch (Exception e) {
            return null;
        }
    }

    /**
     * 获取用户信息
     */
    public static SysUser getUser(){
        Subject subject=getSubject();
        if(subject==null)
            return new SysUser();
        SysUser user=(SysUser) subject.getPrincipal();
        if(user==null)
            return new SysUser();
        return user;
    }

}
